package com.example.common.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.math.BigInteger;
import java.time.LocalDateTime;

@Entity
@Table(name = "sys_menu")
@Data
public class SysMenu {
    @Id
    @Column(name = "menu_id", nullable = false)
    private BigInteger menuId;
    
    // pid
    @ManyToOne
    @JoinColumn(name = "pid", referencedColumnName = "menu_id")
    private SysMenu sysMenu;
    
    @Column(name = "sub_count")
    private Integer subCount;
    
    private Integer type;

    private String title, component, icon, path;
    
    @Column(unique = true)
    private String name;
    
    @Column(name = "menu_sort")
    private Integer menuSort;
    
    @Column(name = "i_frame")
    private Boolean iFrame;
    
    private Boolean cache, hidden;
    
    @Column(unique = true)
    private String permission;
    
    // create_by
    @ManyToOne
    @JoinColumn(name = "create_by", referencedColumnName = "username")
    private SysUser creator;
    
    // update_by
    @ManyToOne
    @JoinColumn(name = "update_by", referencedColumnName = "username")
    private SysUser updator;
    
    @Column(name = "create_time")
    private LocalDateTime createTime;
    
    @Column(name = "update_time")
    private LocalDateTime updateTime;
    
    public String getComponent() {
        return component;
    }
    
    public void setComponent(String component) {
        this.component = component;
    }
    
    public BigInteger getMenuId() {
        return menuId;
    }
    
    public void setMenuId(BigInteger menuId) {
        this.menuId = menuId;
    }
    
    @Transient
    public BigInteger getPid() {
        return sysMenu.getMenuId();
    }
    
    public void setPid(BigInteger pid) {
        SysMenu menu = new SysMenu();
        menu.setMenuId(pid);
        this.sysMenu = menu;
    }
    
    public Integer getSubCount() {
        return subCount;
    }
    
    public void setSubCount(Integer subCount) {
        this.subCount = subCount;
    }
    
    public Integer getType() {
        return type;
    }
    
    public void setType(Integer type) {
        this.type = type;
    }
    
    public Integer getMenuSort() {
        return menuSort;
    }
    
    public void setMenuSort(Integer menuSort) {
        this.menuSort = menuSort;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getIcon() {
        return icon;
    }
    
    public void setIcon(String icon) {
        this.icon = icon;
    }
    
    public String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public String getPermission() {
        return permission;
    }
    
    public void setPermission(String permission) {
        this.permission = permission;
    }
    
    @Transient
    public String getCreateBy() {
        return creator.getUsername();
    }
    
    public void setCreateBy(String createBy) {
        SysUser user = new SysUser();
        user.setUsername(createBy);
        this.creator = user;
    }
    
    @Transient
    public String getUpdateBy() {
        return updator.getUsername();
    }
    
    public void setUpdateBy(String updateBy) {
        SysUser user = new SysUser();
        user.setUsername(updateBy);
        this.updator = user;
    }
    
    public Boolean getIFrame() {
        return iFrame;
    }
    
    public void setIFrame(Boolean iFrame) {
        this.iFrame = iFrame;
    }
    
    public Boolean getCache() {
        return cache;
    }
    
    public void setCache(Boolean cache) {
        this.cache = cache;
    }
    
    public Boolean getHidden() {
        return hidden;
    }
    
    public void setHidden(Boolean hidden) {
        this.hidden = hidden;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
}
